package day13;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Demo<T> {


    private  T t;

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public static void set(Demo<? extends List> lists){
        System.out.println(lists.getT());
    }

    public static void main(String[] args) {
        int[] j ={1,2,8,9,19,20,3,21};

        Arrays.sort(j);
        int result=select(j,21);
        System.out.println(result);

        Demo<String> demo = new Demo<>();
        demo.setT("111111111111111");
        System.out.println(demo.getT());

        Demo<Integer> integerDemo = new Demo<>();
        integerDemo.setT(111);
        System.out.println(integerDemo.getT());

        Demo<ArrayList> d = new Demo<>();
        ArrayList list = new ArrayList();
        list.add(1);
        d.setT(list);

        set(d);
    }

    private static int select(int[] j ,int key) {
        int l=0;
        int r=j.length-1;
        while (l<=r){
            int m =(l+r)/2;
            if(key==j[m]){
                return m;
            }
            if(key>j[m]){
                l=m+1;
                return l;
            }
            if(key<j[m]){
                r=m-1;
                return r;
            }
        }
        return -1;
    }

}
